<template>
  <div>
    <a-form ref="formDataRef" autocomplete="off" name="basic" :model="formState" :label-col="{ style: 'width:80px' }" :wrapper-col="{ style: 'calc(100% - 80px)' }" @finish="onSubmit">
      <a-form-item label="时间" name="content" :rules="[{ required: true, message: '请选择时间!' }]">
        <a-date-picker v-model:value="formState.nodeTime" show-time />
      </a-form-item>

      <a-form-item label="轨迹名称" name="content" :rules="[{ required: true, message: '请输入轨迹名称!' }]">
        <a-textarea v-model:value="formState.content" placeholder="请输入轨迹名称" :maxlength="100" show-count></a-textarea>
      </a-form-item>

      <a-form-item :wrapper-col="{ offset: 8, span: 16 }" class="submit-btn-form-item">
        <a-button :loading="loading" type="primary" html-type="submit" v-debounce>确定</a-button>
        <a-button @click="resetForm">取消</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script setup lang="ts">
import { toRefs, watch } from "vue";
import InitHook from "./composables/initHook";
import OperationHook from "./composables/operationHook";
import dayjs from "dayjs";
const props = withDefaults(
  defineProps<{
    visible: boolean;
    type: number;
    passData: DepartmentPersonnel.ListRows;
  }>(),
  {}
);
const emit = defineEmits<{
  (e: "submit"): void;
  (e: "update:visible", visible: boolean): void;
}>();
const { visible, passData } = toRefs(props);
const { formState, loading, formDataRef } = InitHook();
const { onSubmit, resetForm } = OperationHook({
  visible,
  passData,
  formState,
  loading,
  formDataRef,
  emit
});

const init = () => {
  formState.nodeTime = dayjs(Number(passData.value.nodeTime));
  formState.content = passData.value.content;
};

watch(
  () => visible.value,
  v => {
    if (!v) {
      resetForm();
    } else {
      init();
    }
  }
);
init();
</script>
<style lang="stylus" scoped></style>
